/*
 * @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @Date: 2024-05-09 11:02:48
 * @LastEditors: icymoon911 icymoon911@163.com
 * @LastEditTime: 2024-07-22 21:31:53
 * @FilePath: \ken147258.topayClient\src\api\other\order.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */


import request from "@/utils/request";
import { AxiosPromise } from "axios";

const URL = {
  list: '/platformApi/ms/list', // 获取码商统计列表
  all: '/platformApi/ms/all', // 获取码商列表
  stat: '/platformApi/ms/stat', // 获取所有码商数据，用作下拉列表展示
  add: '/platformApi/ms/add', // 添加码商数据
  edit: '/platformApi/ms/edit', // 编辑码商数据
  delete: '/platformApi/ms/delete', // 删除码商
  pro_modify: '/platformApi/ms/modify', // 码商支付产品更改(状态/费率/最大最小接单金额)
  ms_pro_modify: '/platformApi/ms/ms_pro/modify', // (根据码商ID和通道ID)批量操作(状态/费率/最大最小接单金额)
  amount_list: '/platformApi/ms/amount/list', // 获取码商余额变动列表
  pro_order_list: '/platformApi/ms/pro/list', // 获取码商支付产品列表
  // amount_change: '/platformApi/ms/change', // 码商余额变动
  config_modify: '/platformApi/ms/modify', // 配置修改(接单状态/代付费率)
  pro_order_modify: '/platformApi/ms/pro/modify', // 码商支付产品更改(状态/费率/最大最小接单金额)
  option: '/platformApi/ms/a_key/option',
  amount_change: '/platformApi/ms/amount/change',
  login_clear: '/platformApi/ms/login/clear', // 清除登录（清除登录失败信息）
  google_clear: '/platformApi/ms/google/clear',  // 清除绑定google验证
  tg_bind: '/platformApi/ms/tg/bind',  // 绑定TG
  tg_clear: '/platformApi/ms/tg/clear',  // 解绑TG
  tg_clear_all: '/platformApi/ms/tg/clear_all',  // 一键解绑码商TG
  ms_child: '/platformApi/ms/child',  // 获取码商所有子级
  getLastPayProductRate: '/platformApi/ms/pro/getLastPayProductRate',  // 获取最后操作的渠道费率值
  presetsRate: '/platformApi/ms/pro/presetsRate',  // 预设支付渠道码商的费率
  team_stat: '/platformApi/ms/team/stat',  // 获取码商团队统计列表
};

// 获取码商统计列表
export function list(data: object): AxiosPromise<any> {
  return request({
    url: URL.list,
    method: "get",
    params: data,
  });
}

// 获取码商列表
export function all(data: object): AxiosPromise<any> {
  return new Promise(resolve => {
    request({
      url: URL.all,
      method: "get",
      params: data,
    }).then(res => {
      let result = [...res];

      if (data?.isEdit) {
        result = result.map(item => {
          let displayName = item.ms_name;

          if (item.is_delete === 1) {
            displayName = `${displayName}（已删除）`;
          }

          return {
            ...item,
            ms_name: displayName,
          };
        })
      } else {
        result = result.filter(item => !item.is_delete);
      }


      resolve(result);
    });
  });
}

// 获取所有码商数据，用作下拉列表展示
export function stat(data: object): AxiosPromise<any> {
  return request({
    url: URL.stat,
    method: "get",
    params: data,
  });
}
// 添加码商数据
export function add(data: object) {
  return request({
    url: URL.add,
    method: "post",
    data: data,
  })
}
// 编辑码商数据
export function edit(data: object) {
  return request({
    url: URL.edit,
    method: "post",
    data: data,
  })
}
// 删除码商
export function deleteByIds(data: object) {
  return request({
    url: URL.delete,
    method: "post",
    data: data,
  })
}
// 码商支付产品更改(状态/费率/最大最小接单金额)
export function pro_modify(data: object) {
  return request({
    url: URL.pro_modify,
    method: "post",
    data: data,
  })
}
export function ms_pro_modify(data: object) {
  return request({
    url: URL.ms_pro_modify,
    method: "post",
    data: data,
  })
}
// 获取码商余额变动列表
export function amount_list(data: object) {
  return request({
    url: URL.amount_list,
    method: "get",
    params: data,
  })
}
// 获取码商支付产品列表
export function pro_order_list(data: object) {
  return request({
    url: URL.pro_order_list,
    method: "get",
    params: data,
  })
}
export function ms_child(data: object) {
  return request({
    url: URL.ms_child,
    method: "get",
    params: data,
  })
}
export function team_stat(data: object) {
  return request({
    url: URL.team_stat,
    method: "get",
    params: data,
  })
}
export function getLastPayProductRate() {
  return request({
    url: URL.getLastPayProductRate,
    method: "get",
    // params: data,
  })
}
// 码商余额变动
export function amount_change(data: object) {
  return request({
    url: URL.amount_change,
    method: "post",
    data: data,
  })
}
// 配置修改(接单状态/代付费率)
export function config_modify(data: object) {
  return request({
    url: URL.config_modify,
    method: "post",
    data: data,
  })
}

// 码商支付产品更改(状态/费率/最大最小接单金额)
export function pro_order_modify(data: object) {
  return request({
    url: URL.pro_order_modify,
    method: "post",
    data: data,
  })
}
export function option(data: object) {
  return request({
    url: URL.option,
    method: "post",
    data: data,
  })
}

export function login_clear(data: object) {
  return request({
    url: URL.login_clear,
    method: "post",
    data: data,
  })
}

export function google_clear(data: object) {
  return request({
    url: URL.google_clear,
    method: "post",
    data: data,
  })
}

export function tg_bind(data: object) {
  return request({
    url: URL.tg_bind,
    method: "post",
    data: data,
  })
}

export function tg_clear(data: object) {
  return request({
    url: URL.tg_clear,
    method: "post",
    data: data,
  })
}

export function tg_clear_all(data: object) {
  return request({
    url: URL.tg_clear_all,
    method: "post",
    data: data,
  })
}

export function presetsRate(data: object) {
  return request({
    url: URL.presetsRate,
    method: "post",
    data: data,
  })
}
